import javax.swing.*;
import java.awt.event.*;
import java.io.*;

final class SaveItem extends AbstractAction{
  private final Doer frame;
  SaveItem(String name,Doer frame){
    super(name);
    this.frame=frame;
    putValue(SHORT_DESCRIPTION,name);
    String iconFileName="images"+File.separator+name+".gif";
    if(new File(iconFileName).exists())putValue(SMALL_ICON,new ImageIcon(iconFileName));
  }

    public void actionPerformed(ActionEvent e){
      saveFile();
    }

    public void saveFile(){
      try{
        InterWindow interWindow=(InterWindow)(frame.getTab().getComponentAt(frame.getSelect()));
	File file=new File(interWindow.getDirection(),frame.getTab().getTitleAt(frame.getSelect()));
	FileWriter out=new FileWriter(file);
        JTextArea textArea=interWindow.getTextArea();
	out.write(textArea.getText());
        out.flush();
        out.close();
	frame.getSaveItem().setEnabled(false);
	interWindow.setSaved(true);
	frame.setTitle(file.getName());
      }
      catch(IOException e){
        System.out.println(e);
    }
  }
}
